<template>
  <div>
    <div class="form-page-header">
      <div class="form-page-tool">
        <button
          type="submit"
          @click="submit"
          :disabled="pending"
          class="btn btn-primary"
        >
          提交
        </button>
      </div>
    </div>
    <team-edit :init-data="initData" ref="team"></team-edit>
  </div>
</template>

<script>
import TeamMixi from '@src/modules/teamV2/compoent/TeamMixin.js';
import { openAccurateTab } from '@src/util/platform'
import { PageRoutesTypeEnum } from 'pub-bbx-global/pageType/dist/enum/PageRoutesEnum'
export default {
  name: 'team-edit-view',
  mixins: [TeamMixi],
  methods: {
    submit() {
      let res = this.$refs.team.submit();
      res.then(r => {
        r && r.action === 'create'
          ? this.teamCreate(r, this.createCallBack)
          : this.teamUpdate(r, this.updateCallBack);
      });
    },
    updateCallBack(res) {
      let fromId = window.frameElement.getAttribute('fromid');
      this.$platform.refreshTab(fromId);
      this.goBack(res);
    },
    createCallBack(res) {
      this.goBack(res);
    },
    /* 返回 */
    goBack(res) {
      let id = window.frameElement.dataset.id;
      this.$platform.closeTab(id);
      let fromId = window.frameElement.getAttribute('fromid');
      if (
        res.action == 'create'
        || (tag && tag.tagName != res.params.tagName)
      ) {
        // 新建部门或者修改了部门名称 这时候需要刷新下部门树
        localStorage.setItem('dept-need-refresh', 1);

        openAccurateTab({
          type: PageRoutesTypeEnum.PageSecurityDepartment,
          reload: true,
          fromId
        })
      } else {
        this.$platform.refreshTab(fromId);
      }
    }
  }
};
</script>
